package com.zmm.weblog.web.convert;

import com.zmm.weblog.common.domain.dos.ArticleDo;
import com.zmm.weblog.web.module.vo.archive.FindArchiveArticleRspVo;
import com.zmm.weblog.web.module.vo.article.FindIndexArticlePageListRspVo;
import com.zmm.weblog.web.module.vo.category.FindCategoryArticlePageListRspVo;
import com.zmm.weblog.web.module.vo.tag.FindTagArticlePageListRspVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * @Author: 福禄寿
 * @Date: 2024/7/9 上午10:10
 * @Des: weblog-springboot
 **/

@Mapper
public interface ArticleConvert {

    /**
     * 初始化 convert 实例
     */
    ArticleConvert INSTANCE = Mappers.getMapper(ArticleConvert.class);

    /**
     * 将DO转VO
     */
    @Mapping(target = "createDate", expression = "java(java.time.LocalDate.from(articleDO.getCreateTime()))")
    FindIndexArticlePageListRspVo convertDO2VO(ArticleDo articleDO);

    @Mapping(target = "createDate", expression = "java(java.time.LocalDate.from(articleDO.getCreateTime()))")
    @Mapping(target = "createMonth", expression = "java(java.time.YearMonth.from(articleDO.getCreateTime()))")
    FindArchiveArticleRspVo convertDO2ArchiveVO(ArticleDo articleDO);

    @Mapping(target = "createDate", expression = "java(java.time.LocalDate.from(articleDO.getCreateTime()))")
    FindCategoryArticlePageListRspVo convertDO2CategoryArticleVO(ArticleDo articleDO);

    @Mapping(target = "createDate", expression = "java(java.time.LocalDate.from(articleDO.getCreateTime()))")
    FindTagArticlePageListRspVo convertDO2TagArticleVO(ArticleDo articleDO);
}
